<template>
	<view class="mainpadding2" v-if="pageShow">
		<view class="mainpadding_top ffffff radius">
			<view class="titletext hei_text bold">订单商品</view>
			<view class="flexleft margin_top"  v-for="(item,index) in dataAll.goods" :key="item.id">
				<image :src="item.image_text" class="listleftimg3 margin_right" mode=""></image>
				<view class="flexcolumnbet" style="height: 140rpx;width: 100%;">
					<view class="main_size xiaohei lianghang">{{item.title}}</view>
					<view class="flexbetween" style="width: 100%;">
						<view class="titletext xiaohuang bold">{{item.price}}</view>
						<view class="xiaohui main_size">*{{item.number}}</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 订单状态:1=待支付,3=待核销,6=已完成,7=已取消-->
		<view class="mainpadding_top flexcolumn ffffff radius" v-if="dataAll.state==3">
			<uqrcode ref="uqrcode" canvas-id="qrcode"  @click="ewmfn" v-bind:value="qrcodeurl" :options="{ margin: 10,}"
				size="100">
			</uqrcode>
			<view class="titletext hei_text margin_top bold">核销码</view>
		</view>
		<view class="mainpadding_top ffffff radius" v-if="dataAll.state!=6">
			<view class="titletext hei_text bold">使用门店</view>
			<view class="flexbetween xiahuaxian margin_top" v-for="item in dataAll.shopinfo" :key="item.id">
				<view class="">
					<view class="main_size xiaohei bold">{{item.name}}</view>
					<view class="xiankuan margin_top" style="width: 500rpx;">
						<text class="xiaohuang ershiba margin_right2">距您{{returnKmUnit(Number(item.distance))}}</text>
						<text class="xiaohui ershiba">{{item.address}}</text>
					</view>
				</view>
				<view class="daohang" @click="openmap(item)"></view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius"  v-if="dataAll.state==6">
			<view class="titletext hei_text bold">核销门店</view>
			<view class="flexbetween xiahuaxian margin_top">
				<view class="">
					<view class="main_size xiaohei bold">{{dataAll.scanshop.name}}</view>
					<view class="xiankuan margin_top" style="width: 500rpx;">
						<text class="xiaohuang ershiba margin_right2">距您{{returnKmUnit(Number(dataAll.scanshop.distance))}}</text>
						<text class="xiaohui ershiba">{{dataAll.scanshop.address}}</text>
					</view>
				</view>
				<view class="daohang" @click="openmap(dataAll.scanshop)"></view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="flexbetween">
				<view class="main_size xiaohei bold">支付积分</view>
				<view class="main_size xiaohuang">{{dataAll.pay_price}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="main_size xiaohei bold">订单编号</view>
				<view class="main_size xiaohui">{{dataAll.order_no}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="main_size xiaohei bold">下单时间</view>
				<view class="main_size xiaohui">{{dataAll.createtime_text}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="dataAll.hx_time_text">
				<view class="main_size xiaohei bold">核销时间</view>
				<view class="main_size xiaohui">{{dataAll.hx_time_text}}</view>
			</view>
			<view class="" v-if="dataAll.remarks">
				<view class="main_size xiaohei bold margin_top">备注</view>
				<view class="main_size xiaohui margin_top">{{dataAll.remarks}}</view>
			</view>
		</view>
		<view class="gudingdb ffffff mainpadding flexright">
			<view class="flexright margin_top">
				<view class="listbtnhui margin_left" v-if="dataAll.state==1 || dataAll.state==3" @click.stop="currentid=dataAll.id;showModal('是否确认取消订单？')">取消订单</view>
				<view class="listbtnlan margin_left" v-if="dataAll.state==1" @click.stop="pay(dataAll)">立即支付</view>
				<view class="listbtnhui margin_left" v-if="dataAll.state==6 || dataAll.state==7" @click.stop="currentid=dataAll.id;showModal('是否确认删除当前订单？')">删除订单</view>
				
			</view>
		</view>
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				qrcodeurl:'',
				listid:"",
				dataAll:{},
				pageShow:false,
				lat:"",
				lng:"",
				isLoad:false,
				modal:{
					modalShow:false,
					title:"",
				},
				currentid:"",
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.qrcodeurl = options.id
			// #ifdef APP-PLUS
			this.getLocation()
			// #endif
			// #ifdef H5
			this.getDetail()
			// #endif
		},
		onShow() {
			if(this.isLoad){
				this.getDetail()
			}
		},
		methods: {
			getLocation() {
				let _this = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						uni.hideLoading()
						console.log(res, "获取定位成功");
						_this.lat = res.latitude
						_this.lng = res.longitude
						_this.getDetail()
					},
					fail(err) {
						uni.hideLoading()
					}
				});
			},
			getDetail(){
				httpRequest.request('/api/order/getOrderInfo', 'GET', {
					id: this.listid,
					lat:this.lat,
					lng:this.lng,
				}).then(res => {
					this.isLoad = true
					this.dataAll = res.data
					this.pageShow = true
				})
			},
			// 二维码点击预览图片
			ewmfn() {
				this.$refs.uqrcode.toTempFilePath({
					success: res => {
						console.log(res);
						var i = [res.tempFilePath]; //获取当前页面的轮播图数据
						//uniapp预览轮播图
						uni.previewImage({
							current: 0, //预览图片的下标
							urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
						})
					}
				});
			},
			showModal(val){
				this.modal.title = val
				this.modal.modalShow = true
			},
			modalSure(){
				if(this.modal.title=="是否确认取消订单？"){
					this.cancelorder()
				}else if(this.modal.title=="是否确认删除当前订单？"){
					this.delOrder()
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			cancelorder(){
				httpRequest.request('/api/order/cancelOrder', 'GET', {
					order_id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.getDetail()
					}
				})
			},
			delOrder(){
				httpRequest.request('/api/order/delOrder', 'POST', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			pay(item){
				let data = {
					pay_price:item.total_price,
					type:1,
					order_id:item.id
				}
				uni.navigateTo({
					url:"/pages_index/zhifu?msg="+encodeURIComponent(JSON.stringify(data))
				})
			},
			openmap(item){
				uni.openLocation({
				     latitude: Number(item.latitude),//即将传到高德或腾讯地图的终点纬度  必须是数值，字符串无效
				     longitude:Number(item.longitude),//即将传到高德或腾讯地图的终点经度  必须是数值，字符串无效
				     name: item.address,//即将传到高德或腾讯地图的店铺名称
				     address: item.address,//即将传到高德或腾讯地图的详细地址
				     scale: 18
				})
			}
		}
	}
</script>

<style>

</style>
